
angular.module('mamApp').controller('programOverviewController', ['$scope', 'reportManager', '$state','ImsAlert','paramsManager','api',
    function ($scope, reportManager, $state,ImsAlert,paramsManager,api) {

    $scope.search = {
        status:$state.params.status,
        pageNo:$state.params.pageNo || 1,
        pageSize:$state.params.pageSize||10,
        startTime: $state.params.startTime||null,
        endTime: $state.params.endTime||null,
        "X-Auth-Token":$scope.userInfo.token

    };

    $scope.paginationConf = {
        currentPage: $state.params.pageNo || 1,
        itemsPerPage: $state.params.pageSize || 10,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, $scope.search)
        }
    };

    $scope.rangeDate = {
        startDate:$scope.search.startTime ? moment($scope.search.startTime).format('X'):null,
        endDate:$scope.search.endTime? moment($scope.search.endTime).format('X'):null,
        onSelected: function (data, scope) {  //时间选择确认事件
            $scope.search.startTime=data.startDate?moment(new Date(parseFloat(data.startDate)*1000)).format("YYYY-MM-DD"):null;
            $scope.search.endTime=data.endDate?moment(new Date(new Date(parseFloat(data.endDate)*1000))).format("YYYY-MM-DD"):null;
            $scope.search.pageNo=1;
            $state.go($state.current.name,$scope.search);

        }


    };
    //下载
    $scope.downHref=api+"/cp/exportProgramSummary"+paramsManager.query($scope.search);


    reportManager.programList([$scope.search.pageNo, $scope.search.pageSize],$scope.search).then(function (result) {
        $scope.dataList = result.data.pageList;
        $scope.paginationConf.totalItems = result.data.total;

        var programData = result.data.imgList;
        var tmp=[];
        var duration=[];

        if(programData){
            tmp= [{value: programData.programAlready, name: "已通过"}, {value: programData.programNot, name: "未通过"},
                {value: programData.programPending, name: "待审核"}];
            duration = [{value: programData.alreadyTime, name: "已通过"}, {value: programData.notTime, name: "未通过"},
                {value: programData.pendingTime, name: "待审核"}];
        }else{
            tmp= [{value: 0, name: "已通过"}, {value:0, name: "未通过"},
                {value: 0, name: "待审核"}];
            duration= [{value: 0, name: "已通过"}, {value:0, name: "未通过"},
                {value: 0, name: "待审核"}];
        }
        programDataInit(tmp);
        durationDataInit(duration)

    });

    //饼图


    function programDataInit(data) {
        $scope.programOption = {
            title: {
                text: ' 节目审核',
                x: 'center',
                textStyle:{
                    fontSize:16,
                    fontWeight:500,
                    color:'#000',
                    fontFamily:'Microsoft Yahei',
                }
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['已通过', '未通过', '待审核']
            },
            series: [
                {
                    name: '节目审核',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: data,
                    color:['#4285f4', '#ea4335','#fbbc05'],
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
    }

    function durationDataInit(data) {
            $scope.durationOption = {
                title: {
                    text: ' 时长审核',
                    x: 'center',
                    textStyle:{
                        fontSize:16,
                        fontWeight:500,
                        color:'#000',
                        fontFamily:'Microsoft Yahei',
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['已通过', '未通过', '待审核']
                },
                series: [
                    {
                        name: '时长审核',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data,
                        color:['#4285f4', '#ea4335','#fbbc05'],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
        }


}])


